﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MachineVision.Core.Extensions
{
    public static class SetTimeHelper
    {

        /// <summary>
        /// 可以用于测量任何一个 Action 委托所对应的代码块的执行时间。
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public static long SetTimer(this Action action)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            stopwatch.Start();
            action();
            stopwatch.Stop();
            //返回计时器记录的时间，单位是毫秒。
            return stopwatch.ElapsedMilliseconds;
        }
    }
}
